package com.dialogutils;

import android.app.NotificationManager;
import android.content.Context;
import androidx.core.app.NotificationCompat;
import com.tools.R;

public class Notifications {
    private NotificationCompat.Builder builder;
    private NotificationManager manager;
    private static Notifications notifi;
    private static final int NO_3 =0x3;
    private String mContentTitle;
    private String mContentText;
    private Context mContext;

    public static Notifications getInstance(){
        if(notifi==null){
            notifi=new Notifications();
        }
        return notifi;
    }

    public Notifications(){}

    public Notifications(Context context){
        this.mContext=context;
    }

    public Notifications setContentTitle(String title){
        this.mContentTitle=title;
        return this;
    }

    public Notifications setContentText(String text){
        this.mContentText=text;
        return this;
    }

    public void showNotifi(Context context){
        builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.download_img);
        builder.setContentTitle(mContentTitle);
        builder.setContentText(mContentText);

        manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(NO_3, builder.build());
        builder.setProgress(100, 0, false);
    }

    public Notifications updateNotifi(int progress){
        builder.setProgress(100,progress,false);
        manager.notify(NO_3, builder.build());
        builder.setContentText("下载" +progress+ "%");
        return this;
    }

    public Notifications cancelNotifi(){
        manager.cancel(NO_3);
        return this;
    }
}